package com.neusoft.ysu.his.controller;


import com.neusoft.ysu.his.entity.CommonResult;
import com.neusoft.ysu.his.entity.Patient;
import com.neusoft.ysu.his.service.IPatientService;
import lombok.experimental.PackagePrivate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者：赵子鉴
 * @since 2023-08-25
 */
@RestController
@RequestMapping("/patient")
@CrossOrigin
public class PatientController {
    @Autowired
    IPatientService patientService;

    @PutMapping("/add")
    public CommonResult add(@RequestBody Patient patient){
        patient.setId(null);
        patient.setDelmark(1);
//        System.out.println("patient:\n"+patient);
        return patientService.add(patient);
    }


    @PostMapping("/del/{id}")
    public CommonResult deleteById(@PathVariable int id){
        return patientService.deleteById(id);
    }
    @PostMapping("/update")
    public CommonResult modDept(@RequestBody Patient dept){
        return patientService.update(dept);
    }
    @GetMapping("/q/all")
    public CommonResult findAll(){
        return patientService.selectAll();
    }
    @GetMapping("/q/byid/{id}")
    public CommonResult findById(@PathVariable int id){
        return patientService.selectById(id);
    }

    @PostMapping("/q/num")
    public CommonResult calculateUseNum(@RequestBody Patient patient){return patientService.calculateUseNum(patient);}

    @PostMapping("/updatedelmarkbyid/{id}/{delmark}")
    public CommonResult reDelById(@PathVariable int id,@PathVariable int delmark){
        System.out.println("0:"+id +" "+delmark);
        return patientService.reDelById(id,delmark);
    }
    @GetMapping("/justpay")
    public CommonResult findPaid(){
        return patientService.findPaid();
    }
}
